import java.util.Scanner;

public class Test {
    //思路有点问题
    //8、返回的数字之和（写一个递归方法，输入一个非负整数，返回组成它的数字之和）
    public static int fun(int n) {
        if(n < 10) {
            return n;
        }
        return n % 10 + fun(n / 10);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fun(n));
    }

    //7、递归求解汉诺塔问题
    public static void move(char pos1,char pos2) {
        System.out.println(pos1+" -> "+pos2+" ");
    }

    public static void hanoi(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
        }else {
            hanoi(n - 1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanoi(n - 1,pos2,pos1,pos3);
        }
    }

    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        hanoi(n, 'A', 'B', 'C');
    }

    //6、递归求斐波那契数列的第 n 项
    public static int fib2(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        return fib2(n-1) + fib2(n-2);
    }

    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fib2(n));
    }

    //思路需要注意、有点问题
    //5、递归打印数字的每一位
    public static void print(int n) {
        if(n < 10) {
            System.out.println(n);
        }else {
            print(n / 10);
            System.out.println(n % 10);
        }
    }

    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        print(n);
    }


    //4、递归求和
    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return n + sum(n-1);
    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(sum(n));
    }


    //3、递归求 N 的阶乘
    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        return n * fac(n-1);
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fac(n));
    }




    //2、求最大值方法的重载(在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值)
    public static int max(int a, int b) {
        if(a > b) {
            return a;
        }else {
            return b;
        }
    }

    public static int max(int a, int b ,int c) {
        if(a > b && a > c) {
            return a;
        }else if(c > b && c > a) {
            return c;
        }else {
            return b;
        }
    }

    public static void main2(String[] args) {
        int a = max(1,2);
        int b = max(1,2,3);
        System.out.println(a);
        System.out.println(b);
    }


    //也需要注意
    // 1、斐波那契数列（迭代实现）
    public static int fib1(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = -1;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }


    public static void main1(String[] args) {
        System.out.println(fib1(4));
    }
}
